<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Block_Admin_Post_Grid extends Block_Admin_Grid {

	public function __construct() {
		$this->setTitle('Manage Post');
		App::objectSingleton('Core_Cookie')->init('admin', 'post');
	}
	
	protected function _prepareCollection() {
		$collection = App::object('Entity_Post')->getCollection();
		$select = $collection->getSelect();

		if (App::get('id'))
			$select->where("id = ".App::get('id'));
		if (App::get('title'))
			$select->where("title LIKE '%".App::get('title')."%'");
		if (App::get('description'))
			$select->where("description LIKE '%".App::get('description')."%'");
		if (App::get('created_time'))
			$select->where("DATE(created_time) = STR_TO_DATE('".App::get('created_time')."', '%d-%m-%Y')");
		if (App::get('update_time'))
			$select->where("DATE(update_time) = STR_TO_DATE('".App::get('update_time')."', '%d-%m-%Y')");
		return $collection;
	}

	protected function getSortableColumns() {
		return array('title', 'description', 'created_time', 'update_time', 'id');
	}
}